#include <string>
#include <pthread.h>
#include <gloox/gloox.h>
#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/connectionlistener.h>

using namespace gloox;
using namespace std;

class Messanger : public MessageHandler, public ConnectionListener
{
    public:
        Messanger(const string * sJID, const string * pass, const string * dJID);
        ~Messanger();
        virtual void handleMessage(Stanza * stanza, MessageSession * session);
        void connect();
        void disconnect();
        void send(string & msg);
        bool isConnected();
        bool isAuthenticated();
		static bool test(const string * sJID, const string * pass);

    private:
		Client * j;
	    const string * sJID;
	    const string * pass;
	    const string * dJID;
		
		int ping_counter;
		bool shutdown;
		pthread_mutex_t shutdown_mut;
		pthread_t ping_thread;
		static void * start_ping_thread(void *obj);
		void doPing();
		
		bool onTLSConnect(const CertInfo &info);
		void onConnect();
		void onDisconnect(ConnectionError e);
};
